package com.baizhi.cmfz.service.impl;

import com.baizhi.cmfz.service.ActiveService;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.DeliveryMode;
import javax.jms.Queue;

@Service
public class ActiveServiceImpl implements ActiveService {
//	装配jmsTemplate
	@Resource
	private JmsTemplate jmsTemplate;
//	装配队列
	@Resource
	private Queue queue;
	@Override

	public void mqProduct(String product) {
		//设置消息为持久化消息
		jmsTemplate.setDeliveryMode(DeliveryMode.PERSISTENT);
		jmsTemplate.send(queue,(s)->{ return  s.createTextMessage(product); });
	}


	@Override
	public String mqConsumer() {
//		将数据添加到数据库
		String o = (String) jmsTemplate.receiveAndConvert(queue);
		return o;
	}
}
